/**
 * Project Name:dsrs-systemservice-service
 * File Name:GroupServiceImpl.java
 * Package Name:com.bwda.dsrs.systemservice.service.impl;
 * Date:2019年4月28日
 * Copyright (c) 2019, 江苏保旺达软件有限公司 All Rights Reserved.
 */
package com.bwda.dsrs.systemservice.service.impl;

import com.bwda.dsrs.systemservice.domain.Constants;
import com.bwda.dsrs.systemservice.domain.condition.group.GroupCondition;
import com.bwda.dsrs.systemservice.domain.exception.SystemServiceException;
import com.bwda.dsrs.systemservice.domain.po.group.GroupPo;
import com.bwda.dsrs.systemservice.mapper.GroupMapper;
import com.bwda.dsrs.systemservice.service.GroupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 自定义组
 *
 * @author liangjianyong
 * @date 2019/4/13
 */
@Service
public class GroupServiceImpl extends AbstractBaseServiceImpl<GroupPo, GroupCondition, GroupMapper> implements GroupService {

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void insert(GroupPo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        po.setStatus(Constants.StateType.ENABLE);
        super.insert(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public int update(GroupPo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        return super.update(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void updateWithValid(GroupPo po)
        throws SystemServiceException {
        po.setDelFlag(Constants.NOT_DELETED);
        super.updateWithValid(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void delete(Object id) throws SystemServiceException {
        GroupPo groupPo=new GroupPo();
        groupPo.setId((Integer) id);
        groupPo.setDelFlag(Constants.DELETED);
        super.update(groupPo);
    }

    @Override
    public int queryCount(GroupCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryCount(condition);
    }

    @Override
    public List<GroupPo> queryList(GroupCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryList(condition);
    }

    /**
     * 批量删除
     * @param idList
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void batchDelete(List<Integer> idList){
        GroupPo po=new GroupPo();
        po.setIdList(idList);
        po.setDelFlag(Constants.DELETED);
        this.getMapper().update(po);
    }

    /**
     * 根据ID查询明细
     * @param id
     * @return
     */
    @Override
    public GroupPo queryWithDetail(Integer id){
        return this.getMapper().selectWithDetail(id);
    }

    /**
     * 根据userCode查询组织列表
     * @return
     */
    @Override
    public List<GroupPo> queryGroupListByUserCode(String userCode) {
        return this.getMapper().queryGroupListByUserCode(userCode);
    }
}
